<template>
  <el-dialog :visible="ishowdialog" @close="cancelshowdialog">
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="role in roleList" :key="role.id" :label="role.id">
        {{ role.name }}
      </el-checkbox>
    </el-checkbox-group>
    <el-row type="flex" justify="end">
      <el-button type="primary" plain @click="btnOk">确定</el-button>
      <el-button type="primary" plain @click="btnCancel">取消</el-button>
    </el-row>
  </el-dialog>
</template>

<script>
import { getAllroleListApi } from '@/api/setting'
import { getUserDetailsByID } from '@/api/user'
import { EmployeeAssignRoleApi } from '@/api/employee'
export default {
  props: {
    ishowdialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      rolesId: '',
      // 所有角色列表
      roleList: [],
      // 被勾选的角色列表
      checkList: []
    }
  },
  async created() {
    const { rows } = await getAllroleListApi()
    this.roleList = rows
  },
  methods: {
    async  getUserDetails(id) {
      this.rolesId = id
      const { roleIds } = await getUserDetailsByID(id)
      this.checkList = roleIds
    },
    async btnOk() {
      await EmployeeAssignRoleApi({
        id: this.rolesId,
        roleIds: this.checkList
      })
      this.$message.success('添加成功')
      this.$emit('update:ishowdialog', false)
    },
    btnCancel() {
      this.$emit('update:ishowdialog', false)
    },
    cancelshowdialog() {
      this.$emit('update:ishowdialog', false)
    }
  }

}
</script>

<style>

</style>
